// components/pop_up/pop_up.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    types: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgPath: '/images',
    flag: false,
    home: null,
    typeStr: '' //判断是否客服传递
  },

  observers: {
    "types": function (val) {
      console.log("types", val)
      if (val == 'im_chat') {
        wx.setStorageSync('types', val);
        this.setData({
          typeStr: val,
        })
      }
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getserver() {
      //设置tabbar激活项
      const util = require("../../utils/util")
      util.setTabbarActive('plan');
      wx.redirectTo({
        url: '/pages/plan/joinPlan',
      })
    },
    userCard() {
      wx.redirectTo({
        url: '/pages/chengZhangKa/index',
      })
    },
    goback() {
      // wx.redirectTo({
      //   url: '/im/pages/index',
      // }) 
    //  wx.setStorageSync('types','consultants');
      let aa = wx.getStorageSync('types');
      if(this.data.typeStr=='im_chat'){
        wx.setStorageSync('im:redirectUrl','')
        //  wx.navigateTo({
        //   // url: "/pages/service/index",
        //    url:"/pages/consultants/consultants",
        //  })
        wx.navigateBack({
          delta: 1
        });
      }else{
      wx.navigateBack({
              delta: 1
            });
      }
     
 
    }
  },
  lifetimes: {
    attached() {
      const app = getApp();
      this.setData({
        imgPath: app.globalData.imgPath
      });
      const that = this;
      const api = require("../../api/api");
      let home = wx.getStorageSync('home')
      // if (!home) {
      //读取“个人中心”
      api.user.home({
        success(res) {

          const typest = wx.getStorageSync('types');
        
          if (typest == 'im_chat') {
            setTimeout(function () {
              that.setData({
                flag: res.data.data.is_member ? false : true
              })
            }, 5000);
          } else {
        setTimeout(function () {
            that.setData({
              home: res.data.data,
              flag: res.data.data.is_member ? false : true
            })
          }, 5000);
       }
          //保存home到本地缓存
          wx.setStorageSync('home', res.data.data);
        }
      })
      //} 
      // else {
      //   that.setData({
      //     home: home,
      //   })
      // } 

    }
  }
})